#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;

int n, m;
bool left(char c) { return c == '(' || c == '[' || c == '{'; }
bool match(char c, char d) {
  if (d == ')')
    return c == '(';
  else if (d == ']')
    return c == '[';
  else
    return c == '{';
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  string s;
  cin >> s;
  stack<int> st;
  int ans = 0;
  rep(i, 0, s.size() - 1) {
    if (left(s[i]))
      st.push(i);
    else {
      if (st.size() && match(s[st.top()], s[i])) {
        st.pop();
        int j = st.size() ? st.top() : -1;
        ans = max(ans, i - j);
      } else
        st.push(i);
    }
  }
  cout << ans;
  return 0;
}